﻿using System.Collections;

namespace LinqDemo01
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");

            string[] names = { "Alonso", "Zheng", "Smith","Small"};
            var filteredNames = names.Where(n => n.StartsWith('S'));
            var queryResults = from name in names
                              where name.StartsWith('S')
                              select name;

            foreach (var result in queryResults)
            {
                Console.WriteLine(result);
            }

            queryResults = from name in names
                           where name.StartsWith('S')
                           orderby name
                           select name;

            foreach (var result in queryResults)
            {
                Console.WriteLine(result);
            }

            int[] ints = GenerateLotsOfNumbers(12045678);
            Console.WriteLine($"Start Time: {DateTime.Now.ToString("HH:mm:ss.fff")}");
            var queryResultInt = from num in ints
                           where num > 1000
                           select num;
            Console.WriteLine($"End Time: {DateTime.Now.ToString("HH:mm:ss.fff")}");
            Console.ReadKey();
        }

        static int[] GenerateLotsOfNumbers(int count)
        {
            Random random = new Random(0);
            int[] result = new int[count];
            for (int i = 0; i < count; i++)
            {
                result[i] = random.Next();
            }
            return result;
        }
    }
}
